SPI Engine: fix off-by-one sleep time #1429
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes error seen in #1389
Somewhat recently, during #1200, while fixing a related bug, I altered the documentation to reflect what was then the behavior of the SPI Engine for the Sleep instruction: it slept for
t
prescaler ticks.What I didn't realize back then was that the intended behavior, as seen on the first SPI Engine commit, is to sleep for
t+1
ticks, and that there had been a regression in the meantime.To illustrate, I've made some simple tests, which call the sleep instruction with a parameter of t=4. Expected behavior is for it to sleep for
t+1
ticks, as seen on first commit and as has been documented in the old wiki.This is with the current main (counts only
![image](https://private-user-images.githubusercontent.com/6852873/361866496-d7138ee2-8bb7-4ac6-aa9f-d36ecf5ffa74.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTA5MzAsIm5iZiI6MTczOTAxMDYzMCwicGF0aCI6Ii82ODUyODczLzM2MTg2NjQ5Ni1kNzEzOGVlMi04YmI3LTRhYzYtYWE5Zi1kMzZlY2Y1ZmZhNzQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTAzMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Yjg5Zjk2MmIzYWNkMGExZDVmNjc1NjljNjExZjA4YjlkNDMxNjhiYmQ4MmI2MjVmZWVkZTcyMmE0YWZiNWRmMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.IXfG1V4t-v4brlRbBA82R7AwfiInnDFQO4yb7ED_x9U)
t
ticks):This is how it was before #1200
![image](https://private-user-images.githubusercontent.com/6852873/361867333-64d1d9ac-46f3-420c-a9ee-ee1b4c4038cf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTA5MzAsIm5iZiI6MTczOTAxMDYzMCwicGF0aCI6Ii82ODUyODczLzM2MTg2NzMzMy02NGQxZDlhYy00NmYzLTQyMGMtYTllZS1lZTFiNGM0MDM4Y2YucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTAzMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDhhZmU5OGEwMGVhYmU5ZGIzZWIxYzg3Zjc3Njk1MWIxZWFmZWY1OTk2MjE2MDdmNzk1MThkNTU3YzY2NTk2NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.-B9ujohXyMBoIz5Xoh5y3LMyVGc7N8MY4WivnktwpnE)
(before I changed the doc), it counts each tick as double the duration - that was the bug being solved, but is not relevant to the current PR. At this point, there had already been a regression (counts only
t
ticks):This is the behavior on the first commit for the SPI Engine (counts the correct number of
![image](https://private-user-images.githubusercontent.com/6852873/361871749-25ed1181-6108-43b1-8ef6-910de5942416.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTA5MzAsIm5iZiI6MTczOTAxMDYzMCwicGF0aCI6Ii82ODUyODczLzM2MTg3MTc0OS0yNWVkMTE4MS02MTA4LTQzYjEtOGVmNi05MTBkZTU5NDI0MTYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTAzMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDMxNGE3NmVkMjUyODljYzM5ZTgzZDY4YmEyNWM2YTMwZmMwMGU1MWY5Mzc0Y2ZjY2FjZjYyZTNlYWIxNGRhNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.cmXlVkdggxAHhRidYxq9i-FZuQ3OD_bWngQreWh49tM)
t+1
ticks):PR Type
PR Checklist